

const geoserverUtils = {
    /**
     *
     * @param serverUrl
     * @param typeName
     * @param lng
     * @param lat
     * @param propertyName 默认使用the_geom(一般不用设置)
     */
    getFeatureByPoint(serverUrl, typeName, lng, lat, propertyName) {
        propertyName = propertyName ? propertyName : "the_geom";
        let resource = Cesium.Resource.fetchJson({
            url: serverUrl,
            queryParameters: {
                service: 'WFS',
                request: 'GetFeature',
                version: '1.0.0',
                typeName: typeName,
                maxFeatures: '1',
                outputFormat: 'application/json',
                filter: `<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><Intersects><PropertyName>${propertyName}</PropertyName><gml:Point><gml:coordinates>${lng},${lat}</gml:coordinates></gml:Point></Intersects></Filter>`,
            },
        })
        return resource;
    },

    /**
     *
     * @param serverUrl
     * @param typeName
     * @param lng
     * @param lat
     * @param propertyName 默认使用the_geom(一般不用设置)
     */
    getFeatureByField(serverUrl, typeName, field, value) {
        let resource = Cesium.Resource.fetchJson({
            url: serverUrl,
            queryParameters: {
                service: 'WFS',
                request: 'GetFeature',
                version: '1.0.0',
                typeName: typeName,
                // maxFeatures: '100',
                outputFormat: 'application/json',
                cql_filter: `${field}=${value}`
            },
        })
        return resource;
    }
}

export default geoserverUtils;
